package lab

import "fmt"

// At 根据给定的多个下标从原数组中提取元素，返回一个新的数组
func At[T any](array []T, indices ...int) ([]T, error) {
	result := make([]T, 0, len(indices))
	for _, index := range indices {
		if index < 0 || index >= len(array) {
			return nil, fmt.Errorf("index %d out of bounds", index)
		}
		result = append(result, array[index])
	}
	return result, nil
}
